<template>
  <div class="app-container">
    <el-drawer
      v-if="drawer"
      size="75%"
      :show-close="false"
      :with-header="false"
      :wrapper-closable="false"
      :visible.sync="drawer"
      :before-close="handleClose"
    >
      <userInfo :rows="info" />
      <!-- 关闭按钮 -->
      <div class="close" @click="handleClose"><i class="el-icon-close" /></div>
    </el-drawer>

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>报名信息</span>
      </div>
      <div class="list-search">
        <el-select style="width: 200px;"
          v-model="exam_id"
          placeholder="请选择考试"
          class="list-options"
          @change="funSearch"
        >
          <el-option
            v-for="(item, index) in examList"
            :key="index"
            :label="item.post_title"
            :value="item.id"
          />
        </el-select>
        <el-select
          v-model="pay_status"
          placeholder="支付状态"
          class="list-options"
          @change="funSearch"
        >
          <el-option label="不限支付状态" value="all" />
          <el-option label="未支付" value="0" />
          <el-option label="已支付" value="1" />
        </el-select>
        <el-select
          v-model="review_status"
          placeholder="审核状态"
          class="list-options"
          @change="funSearch"
        >
          <el-option label="不限审核状态" value="all" />
          <el-option label="未提交" value="0" />
          <el-option label="未审核" value="1" />
          <el-option label="已通过" value="2" />
          <el-option label="已拒绝" value="3" />
        </el-select>
        <el-input
          v-model="keyword"
          placeholder="请输入搜索内容"
          class="input-with-select"
          @keyup.enter.native="funSearchKeyword"
        >
          <el-select
            slot="prepend"
            v-model="key_type"
            placeholder="请选择"
            class="input-sel"
          >
            <el-option label="用户名" value="username" />
            <el-option label="身份证号" value="cardid" />
          </el-select>
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="funSearchKeyword"
          />
        </el-input>
      </div>
      <div class="spaceline" />
      <el-table
        v-loading="listLoading"
        :data="list"
        element-loading-text="Loading"
        fit
        highlight-current-row
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="42" />
        <el-table-column align="center" label="ID" width="80">
          <template slot-scope="scope">
            {{ scope.row.id }}
          </template>
        </el-table-column>
        <el-table-column label="用户名" show-overflow-tooltip >
          <template slot-scope="scope">
              {{ scope.row.user_info.username }}
          </template>
        </el-table-column>
        <el-table-column label="头像" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-avatar size="small" :src="scope.row.user_info.avatar" :key="scope.row.user_info.avatar"></el-avatar>
          </template>
        </el-table-column>
        <el-table-column label="报名岗位" show-overflow-tooltip>
          <template slot-scope="scope">
              {{ scope.row.career_name }}
          </template>
        </el-table-column>
        <el-table-column label="手机" show-overflow-tooltip>
          <template slot-scope="scope">
              {{ scope.row.mobile }}
          </template>
        </el-table-column>
        <el-table-column label="审核状态" show-overflow-tooltip >
          <template slot-scope="scope">
            <el-badge :value="scope.row.review_count" class="item">
              <!-- 0 未提交 1已提交 2 已通过 3 未通过 -->
              <el-tag :type="scope.row.review_status_class"
                        disable-transitions>{{scope.row.review_status_txt}}</el-tag>
            </el-badge>
          </template>
        </el-table-column>
        <el-table-column label="支付状态" show-overflow-tooltip>
          <template slot-scope="scope">
              <el-tag :type="scope.row.pay_status_class"
                        disable-transitions>{{scope.row.pay_status_txt}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="created_at"
          label="提审日期"
          width="200"
        >
          <template slot-scope="scope">
            <i class="el-icon-time" />
            <span>{{ scope.row.create_time | timeFilter }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="created_at"
          label="注册日期"
          width="200"
        >
          <template slot-scope="scope">
            <i class="el-icon-time" />
            <span>{{ scope.row.reg_time | timeFilter }}</span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" min-width="150">
          <template slot-scope="scope">
            <el-button
              size="small"
              type="primary"
              @click="see(scope.row,'first')"
            >
              审核
            </el-button>
            <el-button
              size="small"
              type="danger"
              @click="see(scope.row,'memberInformation')"
            >
              查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="spaceline" />
      <el-row :gutter="20">
        <el-col :span="8">
          <!-- <el-button size="small" type="primary" @click="goTo('add')">
            添加资讯
          </el-button> -->
          <!-- <el-button size="small" type="primary" @click="displayStatus">
            显示状态
          </el-button>
          <el-button size="small" type="danger" @click="funDeleteBatch">
            删除所选
          </el-button> -->
        </el-col>
        <el-col :span="16" style="text-align: right;">
          <el-pagination
            background
            :current-page="currentPage"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </el-col>
      </el-row>
    </el-card>


    <!-- <el-dialog title="将显示状态设置为" :visible.sync="dialogFormVisible" width="27%">
      <el-form class="common-form" label-width="80px">
        <el-form-item label="显示状态">
          <el-radio-group v-model="display">
            <el-radio label="1">显示</el-radio>
            <el-radio label="0">隐藏</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="fun_set_display">确 定</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
  import userInfo from '@/views/kaowu/kaowu/examuser/components/userInfo'
import { examList,examUserList } from '@/api/kaowu/exam'
import { parseTime } from '@/utils/index'

export default {
  filters: {
    displayFilter(is_display) {
      const displayMap = {
        1: 'success',
        0: 'danger'
      }
      return displayMap[is_display]
    },
    timeFilter(timestamp) {
      return parseTime(timestamp, '{y}-{m}-{d} {h}:{i}')
    }
  },
  data() {
    return {
      drawer: false,
      pay_status:'all',
      review_status:'all',
      examList:[],
      tableIdarr: [],
      list: null,
      listLoading: true,
      total: 0,
      currentPage: 1,
      pagesize: 10,
      articleCategory: [],
      articleCategoryLoading: true,
      is_display: '',
      exam_id:null,
      key_type: 'username',
      keyword: ''
    }
  },
  components:{
    userInfo
  },
  created() {
    this.fetchData()
    this.fetchQueryData()
  },
  methods: {
    displayStatus() {
      var that = this
      if (that.tableIdarr.length == 0) {
        that.$message.error('请选择要修改的数据')
        return false
      }
      that.dialogFormVisible = true
    },
    fun_set_display() {
      const that = this
      const param = {
        display: this.display,
        id: this.tableIdarr
      }
      articleModifyState(param).then(response => {
        this.$message.success(response.message)
        this.fetchData()
        this.display = '1'
        that.dialogFormVisible = false
        return true
      }).catch(() => {})
    },
    modifyState(row){
      const that = this
      const param = {
        display: row.display,
        id: [row.id]
      }
      articleModifyState(param).then(response => {
        this.$message.success(response.message)
        this.fetchData()
        return true
      }).catch(() => {
        that.issubmit = false
      })
    },
    fetchData() {
      this.listLoading = true
      const param = {
        review_status: this.review_status,
        pay_status: this.pay_status,
        exam_id: this.exam_id,
        key_type: this.key_type,
        keyword: this.keyword,
        page: this.currentPage,
        pagesize: this.pagesize
      }
      examUserList(param).then(response => {
        this.list = response.data.items
        this.listLoading = false
        this.total = response.data.total
        this.currentPage = response.data.current_page
        this.pagesize = response.data.pagesize
        if(!this.exam_id){
          this.exam_id = response.data.exam_id
        }

      })
    },
    fetchQueryData() {
      const param = {}
      examList(param).then(response => {
        this.examList = response.data.items
      })
    },
    handleSizeChange(val) {
      this.pagesize = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.fetchData()
    },
    funSearch() {
      this.fetchData()
    },
    funSearchKeyword() {
      this.currentPage = 1
      this.fetchData()
    },
    funEdit(index, row) {
      this.drawer = true
    },
    funDelete(index, row) {
      var that = this
      that
        .$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          const param = {
            id: row.id
          }
          articleDelete(param).then(response => {
            that.$message.success(response.message)
            that.fetchData()
            return true
          })
        })
        .catch(() => {})
    },
    funDeleteBatch() {
      var that = this
      if (that.tableIdarr.length == 0) {
        that.$message.error('请选择要删除的数据')
        return false
      }
      that
        .$confirm('此操作将永久删除选中的数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          const param = {
            id: that.tableIdarr
          }
          articleDelete(param).then(response => {
            that.$message.success(response.message)
            that.fetchData()
            return true
          })
        })
        .catch(() => {})
    },
    handleSelectionChange(idlist) {
      this.tableIdarr = []
      if (idlist.length > 0) {
        for (const item of idlist) {
          this.tableIdarr.push(item.id)
        }
      }
    },
    goTo(target) {
      this.$router.push('/kaowu/exam/list/' + target)
    },
    handleClose() {
      this.drawer = false
      this.fetchData()
    },

    see(value,type) {
      this.drawer = true
      value.tabName = type
      this.info = value
    },
  }
}
</script>


<style scoped lang="scss">
  .item {
    margin-top: 10px;
    margin-right: 40px;
  }
  .operation {
    font-size: 14px;
  }
  .close {
    width: 40px;
    height: 60px;
    position: absolute;
    left: -40px;
    top: 50%;
    transform: translateY(-50%);
    background: #f5f5f5;
    border-radius: 8px 0 0 8px;
    cursor: pointer;

    .el-icon-close {
      font-size: 30px;
      color: #777;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
  }

</style>

